#include "MirrorImageSettingsForm.h"
#include "ui_MirrorImageSettingsForm.h"
#include <QDebug>

MirrorImageSettingsForm::MirrorImageSettingsForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MirrorImageSettingsForm),
    m_horizontalMirror(true),
    m_verticalMirror(false)
{
    ui->setupUi(this);
    setAttribute(Qt::WA_StyledBackground, true);
    // 初始化UI - 设置默认选项为水平镜像
    ui->mirrorModeComboBox->setCurrentIndex(0); 
}

MirrorImageSettingsForm::~MirrorImageSettingsForm()
{
    delete ui;
}

void MirrorImageSettingsForm::setMirrorMode(bool horizontal, bool vertical)
{
    m_horizontalMirror = horizontal;
    m_verticalMirror = vertical;

    // 根据镜像模式设置下拉列表的当前选项
    if (!horizontal && !vertical) {
        ui->mirrorModeComboBox->setCurrentIndex(0); // 无镜像
    } else if (horizontal && !vertical) {
        ui->mirrorModeComboBox->setCurrentIndex(1); // 水平镜像
    } else if (!horizontal && vertical) {
        ui->mirrorModeComboBox->setCurrentIndex(2); // 垂直镜像
    }
}

void MirrorImageSettingsForm::mirrorMode(bool &horizontal, bool &vertical) const
{
    horizontal = m_horizontalMirror;
    vertical = m_verticalMirror;
}

void MirrorImageSettingsForm::on_mirrorModeComboBox_currentIndexChanged(int index)
{
    bool oldHorizontal = m_horizontalMirror;
    bool oldVertical = m_verticalMirror;

    // 根据下拉列表的当前选项更新镜像方式
    switch (index) {
    case 0: // 无镜像
        m_horizontalMirror = false;
        m_verticalMirror = false;
        break;
    case 1: // 水平镜像
        m_horizontalMirror = true;
        m_verticalMirror = false;
        break;
    case 2: // 垂直镜像
        m_horizontalMirror = false;
        m_verticalMirror = true;
        break;
    case 3:// 水平且垂直镜像
        m_horizontalMirror=true;
        m_verticalMirror = true;
        break;
    default:
        m_horizontalMirror = false;
        m_verticalMirror = false;
        break;
    }

    // 如果设置发生变化，发出信号
    if (oldHorizontal != m_horizontalMirror || oldVertical != m_verticalMirror) {
        emit settingsChanged();
    }
}
